package cz.mpelant.msoe.mealchecker.request;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.Header;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.message.BasicHeader;

import android.util.Log;
import cz.mpelant.msoe.mealchecker.downloader.URLBuilder;

public abstract class RequestType {
    private static final String TAG = "RequestType";
	protected HttpUriRequest request;
	protected URLBuilder requestUrl;
	private List<Header> headers;

	protected RequestType(String url) {
		headers=new ArrayList<Header>();
		requestUrl = new URLBuilder(url);
	}

	public HttpUriRequest getHttpRequest() {
		request.setHeaders((BasicHeader[]) headers.toArray(new BasicHeader[0]));
		return request;
	}

	protected void addHeader(String name, Object value) {
		if (value != null)
			headers.add(new BasicHeader(name, value.toString()));
		Log.d(TAG, "Header: " + name + ":" + value.toString());
	}

	protected void addParameters(String name, Object value) {
		if (value != null)
			requestUrl.addParameters(name, value.toString());
	}
}
